package com.lqk.channel.filechannel;

import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 通道之间数据传输
 */
public class FileChannelDemo3 {

    /*
        transferFrom() 方法
     */
    public static void main(String[] args) throws Exception {
        // 创建两个 FileChannel
        RandomAccessFile accessFile = new RandomAccessFile("F:\\lqk\\001.txt", "rw");
        FileChannel fromChannel = accessFile.getChannel();

        RandomAccessFile accessFile2 = new RandomAccessFile("F:\\lqk\\002.txt", "rw");
        FileChannel toChannel = accessFile2.getChannel();

        // fromChannel 中的数据传输到 toChannel
        long position = 0;
        long size = fromChannel.size();
        toChannel.transferFrom(fromChannel, position, size);

        accessFile.close();
        accessFile2.close();
        System.out.println("over!");


    }
}
